package com.git.smp.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.git.smp.dao.SmpUserRoleMapper;
import com.git.smp.entity.Role;
import com.git.smp.entity.SmpUserRole;
import com.git.smp.entity.UserRoleEx;

@RestController
@RequestMapping("/userRole")
public class SmpUserRoleController {
	
	Logger logger = LoggerFactory.getLogger(SmpUserRoleController.class);
	
	@Autowired
	SmpUserRoleMapper smpUserRoleMapper;
	
	//维护用户角色表信息
	@RequestMapping("/maintenanceInfo")
	@Transactional
	public void maintenanceInfo(
			@RequestBody UserRoleEx userRoleEx)
	{
		smpUserRoleMapper.delByUserName(userRoleEx.getUserName());
		SmpUserRole smpUserRole = new SmpUserRole();
		smpUserRole.setUserName(userRoleEx.getUserName());
		for (Role role : userRoleEx.getListRole()) {
			smpUserRole.setRoleId(role.getId());
			smpUserRoleMapper.insert(smpUserRole);
		}
	}

}
